package rad.framework.mda.generator.template.main.java.entity;

import java.util.Iterator;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.*;
import rad.framework.mda.generator.util.*;
import org.eclipse.emf.codegen.util.*;

public class EntityClass
{
  protected static String nl;
  public static synchronized EntityClass create(String lineSeparator)
  {
    nl = lineSeparator;
    EntityClass result = new EntityClass();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "";
  protected final String TEXT_2 = "/*" + NL + " * ============================================================================" + NL + " *                   GNU Lesser General Public License" + NL + " * ============================================================================" + NL + " */" + NL + "package ";
  protected final String TEXT_3 = ";";
  protected final String TEXT_4 = NL;
  protected final String TEXT_5 = NL;
  protected final String TEXT_6 = NL + NL + "/**" + NL + " * ";
  protected final String TEXT_7 = NL + " *" + NL + " * @author ";
  protected final String TEXT_8 = NL + " * @generated" + NL + " */";
  protected final String TEXT_9 = NL;
  protected final String TEXT_10 = NL;
  protected final String TEXT_11 = NL + "public class ";
  protected final String TEXT_12 = " {" + NL + "\t/** @generated */" + NL + "\tprivate static final long serialVersionUID = 1L;" + NL + "" + NL + "\t/** @generated */" + NL + "\tpublic ";
  protected final String TEXT_13 = "() {" + NL + "\t}";
  protected final String TEXT_14 = NL + NL + "\t/**" + NL + "\t * ------------------------------------------------------------------------" + NL + "\t * ";
  protected final String TEXT_15 = NL + "\t * ------------------------------------------------------------------------" + NL + "\t * @generated" + NL + "\t */" + NL + "\t";
  protected final String TEXT_16 = NL + "\tpublic ";
  protected final String TEXT_17 = " ";
  protected final String TEXT_18 = "() {";
  protected final String TEXT_19 = NL + "\t\tif (this.";
  protected final String TEXT_20 = " == null) {";
  protected final String TEXT_21 = NL + "\t\t\tthis.";
  protected final String TEXT_22 = " = new HashSet<";
  protected final String TEXT_23 = ">();";
  protected final String TEXT_24 = NL + "\t\t\tthis.";
  protected final String TEXT_25 = " = new ArrayList<";
  protected final String TEXT_26 = ">();";
  protected final String TEXT_27 = NL + "\t\t}";
  protected final String TEXT_28 = NL + "\t\tif (this.";
  protected final String TEXT_29 = " == null) {" + NL + "\t\t\tthis.";
  protected final String TEXT_30 = " = new ";
  protected final String TEXT_31 = "();        " + NL + "\t\t}";
  protected final String TEXT_32 = NL + "\t\treturn ";
  protected final String TEXT_33 = ";" + NL + "\t}" + NL + "" + NL + "\t/** @generated */" + NL + "\tpublic void set";
  protected final String TEXT_34 = "(final ";
  protected final String TEXT_35 = " ";
  protected final String TEXT_36 = ") {" + NL + "\t\tthis.";
  protected final String TEXT_37 = " = ";
  protected final String TEXT_38 = ";" + NL + "\t}";
  protected final String TEXT_39 = NL + NL + "\t/**" + NL + "\t * Associate ";
  protected final String TEXT_40 = " with ";
  protected final String TEXT_41 = NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void add";
  protected final String TEXT_42 = "(";
  protected final String TEXT_43 = " ";
  protected final String TEXT_44 = ") {" + NL + "\t\tif (";
  protected final String TEXT_45 = " == null) {" + NL + "\t\t\treturn;" + NL + "\t\t}" + NL + "\t\t";
  protected final String TEXT_46 = "().add(";
  protected final String TEXT_47 = ");";
  protected final String TEXT_48 = NL + "\t\t";
  protected final String TEXT_49 = ".get";
  protected final String TEXT_50 = "().add(this);";
  protected final String TEXT_51 = NL + "\t\t";
  protected final String TEXT_52 = ".set";
  protected final String TEXT_53 = "(this);";
  protected final String TEXT_54 = NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * Unassociate ";
  protected final String TEXT_55 = " from ";
  protected final String TEXT_56 = NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void remove";
  protected final String TEXT_57 = "(";
  protected final String TEXT_58 = " ";
  protected final String TEXT_59 = ") {" + NL + "\t\tif (";
  protected final String TEXT_60 = " == null) {" + NL + "\t\t\treturn;" + NL + "\t\t}" + NL + "\t\t";
  protected final String TEXT_61 = "().remove(";
  protected final String TEXT_62 = ");";
  protected final String TEXT_63 = NL + "\t\t";
  protected final String TEXT_64 = ".get";
  protected final String TEXT_65 = "().remove(this);";
  protected final String TEXT_66 = NL + "\t\t";
  protected final String TEXT_67 = ".set";
  protected final String TEXT_68 = "(null);";
  protected final String TEXT_69 = NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void removeAll";
  protected final String TEXT_70 = "() {";
  protected final String TEXT_71 = NL + "\t\tList<";
  protected final String TEXT_72 = "> remove = new ArrayList<";
  protected final String TEXT_73 = ">();" + NL + "\t\tremove.addAll(";
  protected final String TEXT_74 = "());" + NL + "\t\tfor (";
  protected final String TEXT_75 = " element : remove) {" + NL + "\t\t\tremove";
  protected final String TEXT_76 = "(element);" + NL + "\t\t}" + NL + "\t}";
  protected final String TEXT_77 = NL + NL + "\t/** @generated */" + NL + "\t@Transient" + NL + "\tpublic boolean is";
  protected final String TEXT_78 = "() {" + NL + "\t\treturn ";
  protected final String TEXT_79 = ".";
  protected final String TEXT_80 = ".equals(";
  protected final String TEXT_81 = ");" + NL + "\t}";
  protected final String TEXT_82 = NL + NL + "\t/** @generated */" + NL + "\tprivate ";
  protected final String TEXT_83 = " ";
  protected final String TEXT_84 = " = ";
  protected final String TEXT_85 = ";";
  protected final String TEXT_86 = NL + NL + "\t// ------------------------------------------------------------------------" + NL + "\t// Utils" + NL + "\t// ------------------------------------------------------------------------" + NL;
  protected final String TEXT_87 = NL + "\t/** @generated */" + NL + "\t@PreRemove" + NL + "\tpublic void preRemove() {";
  protected final String TEXT_88 = NL + "\t\tremoveAll";
  protected final String TEXT_89 = "();";
  protected final String TEXT_90 = NL + "\t\tremoveAll";
  protected final String TEXT_91 = "();";
  protected final String TEXT_92 = NL + "\t}";
  protected final String TEXT_93 = NL + NL + "\t/** @generated */" + NL + "\tpublic String toString() {" + NL + "\t\treturn ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);" + NL + "\t}";
  protected final String TEXT_94 = NL + "\t" + NL + "\t/** @generated */" + NL + "\tpublic ";
  protected final String TEXT_95 = " deepClone() throws Exception {";
  protected final String TEXT_96 = NL + "\t\t";
  protected final String TEXT_97 = " clone = (";
  protected final String TEXT_98 = ") super.deepClone();";
  protected final String TEXT_99 = NL + "\t\t";
  protected final String TEXT_100 = " clone = (";
  protected final String TEXT_101 = ") super.clone();" + NL + "\t\tclone.setId(null);";
  protected final String TEXT_102 = NL + NL + "\t\tclone.set";
  protected final String TEXT_103 = "(null);" + NL + "\t\tfor (";
  protected final String TEXT_104 = " kid : this.get";
  protected final String TEXT_105 = "()) {" + NL + "\t\t\tclone.add";
  protected final String TEXT_106 = "(kid.deepClone());" + NL + "\t\t}";
  protected final String TEXT_107 = NL + "\t\tclone.set";
  protected final String TEXT_108 = "(this.get";
  protected final String TEXT_109 = "().deepClone());";
  protected final String TEXT_110 = NL + NL + "\t\tclone.set";
  protected final String TEXT_111 = "(null);" + NL + "\t\tfor (";
  protected final String TEXT_112 = " kid : this.get";
  protected final String TEXT_113 = "()) {" + NL + "\t\t\tclone.add";
  protected final String TEXT_114 = "(kid);" + NL + "\t\t}";
  protected final String TEXT_115 = NL + "\t\treturn clone;" + NL + "\t}";
  protected final String TEXT_116 = NL + "\t" + NL + "\t/** @generated */" + NL + "\t@Override" + NL + "\tpublic int hashCode() {" + NL + "\t\tfinal int PRIME = 31;" + NL + "\t\tint result = 1;" + NL + "\t\tresult = PRIME * result + ((id == null) ? super.hashCode() : id.hashCode());" + NL + "\t\treturn result;" + NL + "\t}" + NL + "" + NL + "\t/** @generated */" + NL + "\t@Override" + NL + "\tpublic boolean equals(Object obj) {" + NL + "\t\tif (this == obj)" + NL + "\t\t\treturn true;" + NL + "\t\tif (obj == null)" + NL + "\t\t\treturn false;" + NL + "\t\tif (!(obj instanceof ";
  protected final String TEXT_117 = "))" + NL + "\t\t\treturn false;" + NL + "\t\tfinal ";
  protected final String TEXT_118 = " other = (";
  protected final String TEXT_119 = ") obj;" + NL + "\t\tif (id == null) {" + NL + "\t\t\tif (other.getId() != null)" + NL + "\t\t\t\treturn false;" + NL + "\t\t} else if (!id.equals(other.getId()))" + NL + "\t\t\treturn false;" + NL + "\t\treturn true;" + NL + "\t}\t";
  protected final String TEXT_120 = NL + "}";
  protected final String TEXT_121 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    

    Class uml2Class = (Class) argument;Package uml2Package = uml2Class.getPackage();
    stringBuffer.append(TEXT_1);
    stringBuffer.append(TEXT_2);
    stringBuffer.append(NameHelper.getQualifiedName(uml2Package));
    stringBuffer.append(TEXT_3);
    ImportManager importManager = ImportHelper.makeImportManager("");
    stringBuffer.append(TEXT_4);
    importManager.addImport("org.apache.commons.lang.builder.ToStringBuilder");
    importManager.addImport("org.apache.commons.lang.builder.ToStringStyle");
    stringBuffer.append(TEXT_5);
    
StringBuffer importStringBuffer = stringBuffer;
int importInsertionPoint = stringBuffer.length();
importManager.addCompilationUnitImports(stringBuffer.toString());

    stringBuffer.append(TEXT_6);
    stringBuffer.append(TypeHelper.getDocumentation(uml2Class));
    stringBuffer.append(TEXT_7);
    stringBuffer.append(System.getProperty("user.name"));
    stringBuffer.append(TEXT_8);
    stringBuffer.append(TEXT_9);
    stringBuffer.append(StereotypeHelper.getAnnotations(uml2Class, false));
    if (ClassHelper.isRoot(uml2Class)) {
    stringBuffer.append(TEXT_10);
    stringBuffer.append(ClassHelper.getInheritance(uml2Class));
    }
    stringBuffer.append(TEXT_11);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(ClassHelper.getExtendsAndImplementsLitteral(uml2Class));
    stringBuffer.append(TEXT_12);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_13);
    for (Iterator i=uml2Class.getAttributes().iterator(); i.hasNext();) { Property property = (Property)i.next();
    if (property.getType() !=null) {
    stringBuffer.append(TEXT_14);
    stringBuffer.append(TypeHelper.getDocumentation(property));
    stringBuffer.append(TEXT_15);
    stringBuffer.append(StereotypeHelper.getAnnotations(property));
    stringBuffer.append(TEXT_16);
    stringBuffer.append(TypeHelper.getImportedFeatureType(property));
    stringBuffer.append(TEXT_17);
    stringBuffer.append(ClassHelper.getGetAccessor(property));
    stringBuffer.append(TEXT_18);
    if (property.getAssociation() != null && property.isMultivalued()) {
    stringBuffer.append(TEXT_19);
    stringBuffer.append(NameHelper.uncapSafeName(property));
    stringBuffer.append(TEXT_20);
    if (property.getOpposite() == null || property.getOpposite().isMultivalued()) {
    importManager.addImport("java.util.HashSet");
    stringBuffer.append(TEXT_21);
    stringBuffer.append(NameHelper.uncapSafeName(property));
    stringBuffer.append(TEXT_22);
    stringBuffer.append(TypeHelper.getImportedType(property.getType()));
    stringBuffer.append(TEXT_23);
    } else {
    importManager.addImport("java.util.ArrayList");
    stringBuffer.append(TEXT_24);
    stringBuffer.append(NameHelper.uncapSafeName(property));
    stringBuffer.append(TEXT_25);
    stringBuffer.append(TypeHelper.getImportedType(property.getType()));
    stringBuffer.append(TEXT_26);
    }
    stringBuffer.append(TEXT_27);
    }
    if (ClassHelper.isComposite(property)) {
    stringBuffer.append(TEXT_28);
    stringBuffer.append(NameHelper.uncapSafeName(property));
    stringBuffer.append(TEXT_29);
    stringBuffer.append(NameHelper.uncapSafeName(property));
    stringBuffer.append(TEXT_30);
    stringBuffer.append(TypeHelper.getImportedType(property.getType()));
    stringBuffer.append(TEXT_31);
    }
    stringBuffer.append(TEXT_32);
    stringBuffer.append(NameHelper.uncapSafeName(property));
    stringBuffer.append(TEXT_33);
    stringBuffer.append(ClassHelper.getAccessorName(property));
    stringBuffer.append(TEXT_34);
    stringBuffer.append(TypeHelper.getImportedFeatureType(property));
    stringBuffer.append(TEXT_35);
    stringBuffer.append(NameHelper.uncapSafeName(property));
    stringBuffer.append(TEXT_36);
    stringBuffer.append(NameHelper.uncapSafeName(property));
    stringBuffer.append(TEXT_37);
    stringBuffer.append(NameHelper.uncapSafeName(property));
    stringBuffer.append(TEXT_38);
    if (property.getAssociation() != null && property.isMultivalued()) {
    stringBuffer.append(TEXT_39);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_40);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_41);
    stringBuffer.append(ClassHelper.getAccessorNameNonPlural(property));
    stringBuffer.append(TEXT_42);
    stringBuffer.append(TypeHelper.getImportedType(property.getType()));
    stringBuffer.append(TEXT_43);
    stringBuffer.append(NameHelper.uncapSafeNameNonPlural(property));
    stringBuffer.append(TEXT_44);
    stringBuffer.append(NameHelper.uncapSafeNameNonPlural(property));
    stringBuffer.append(TEXT_45);
    stringBuffer.append(ClassHelper.getGetAccessor(property));
    stringBuffer.append(TEXT_46);
    stringBuffer.append(NameHelper.uncapSafeNameNonPlural(property));
    stringBuffer.append(TEXT_47);
    if (property.getOpposite() != null) {
    if (property.getOpposite().isMultivalued()) {
    stringBuffer.append(TEXT_48);
    stringBuffer.append(NameHelper.uncapSafeNameNonPlural(property));
    stringBuffer.append(TEXT_49);
    stringBuffer.append(ClassHelper.getAccessorName(property.getOpposite()));
    stringBuffer.append(TEXT_50);
    } else {
    stringBuffer.append(TEXT_51);
    stringBuffer.append(NameHelper.uncapSafeNameNonPlural(property));
    stringBuffer.append(TEXT_52);
    stringBuffer.append(ClassHelper.getAccessorName(property.getOpposite()));
    stringBuffer.append(TEXT_53);
    }}
    stringBuffer.append(TEXT_54);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_55);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_56);
    stringBuffer.append(ClassHelper.getAccessorNameNonPlural(property));
    stringBuffer.append(TEXT_57);
    stringBuffer.append(TypeHelper.getImportedType(property.getType()));
    stringBuffer.append(TEXT_58);
    stringBuffer.append(NameHelper.uncapSafeNameNonPlural(property));
    stringBuffer.append(TEXT_59);
    stringBuffer.append(NameHelper.uncapSafeNameNonPlural(property));
    stringBuffer.append(TEXT_60);
    stringBuffer.append(ClassHelper.getGetAccessor(property));
    stringBuffer.append(TEXT_61);
    stringBuffer.append(NameHelper.uncapSafeNameNonPlural(property));
    stringBuffer.append(TEXT_62);
    if (property.getOpposite() != null) {
    if (property.getOpposite().isMultivalued()) {
    stringBuffer.append(TEXT_63);
    stringBuffer.append(NameHelper.uncapSafeNameNonPlural(property));
    stringBuffer.append(TEXT_64);
    stringBuffer.append(ClassHelper.getAccessorName(property.getOpposite()));
    stringBuffer.append(TEXT_65);
    } else {
    stringBuffer.append(TEXT_66);
    stringBuffer.append(NameHelper.uncapSafeNameNonPlural(property));
    stringBuffer.append(TEXT_67);
    stringBuffer.append(ClassHelper.getAccessorName(property.getOpposite()));
    stringBuffer.append(TEXT_68);
    }}
    stringBuffer.append(TEXT_69);
    stringBuffer.append(ClassHelper.getAccessorName(property));
    stringBuffer.append(TEXT_70);
    importManager.addImport("java.util.List");
    importManager.addImport("java.util.ArrayList");
    stringBuffer.append(TEXT_71);
    stringBuffer.append(TypeHelper.getImportedType(property.getType()));
    stringBuffer.append(TEXT_72);
    stringBuffer.append(TypeHelper.getImportedType(property.getType()));
    stringBuffer.append(TEXT_73);
    stringBuffer.append(ClassHelper.getGetAccessor(property));
    stringBuffer.append(TEXT_74);
    stringBuffer.append(TypeHelper.getImportedType(property.getType()));
    stringBuffer.append(TEXT_75);
    stringBuffer.append(ClassHelper.getAccessorNameNonPlural(property));
    stringBuffer.append(TEXT_76);
    }}
    if (TypeHelper.isEnum(property)) {
    for (Iterator l=((Enumeration)property.getType()).getOwnedLiterals().iterator(); l.hasNext();) { EnumerationLiteral enumLiteral = (EnumerationLiteral)l.next();
    importManager.addImport("javax.persistence.Transient");
    stringBuffer.append(TEXT_77);
    stringBuffer.append(NameHelper.getCapName(enumLiteral));
    stringBuffer.append(TEXT_78);
    stringBuffer.append(((Enumeration)property.getType()).getName());
    stringBuffer.append(TEXT_79);
    stringBuffer.append(EnumerationHelper.getEnumLiteralID(enumLiteral));
    stringBuffer.append(TEXT_80);
    stringBuffer.append(NameHelper.uncapSafeName(property));
    stringBuffer.append(TEXT_81);
    }}
    stringBuffer.append(TEXT_82);
    stringBuffer.append(TypeHelper.getImportedFeatureType(property));
    stringBuffer.append(TEXT_83);
    stringBuffer.append(NameHelper.uncapSafeName(property));
    stringBuffer.append(TEXT_84);
    stringBuffer.append(TypeHelper.getDefaultValue(property));
    stringBuffer.append(TEXT_85);
    }
    stringBuffer.append(TEXT_86);
    if (ClassHelper.getAllManyToManyProperties(uml2Class).hasNext()) {
    importManager.addImport("javax.persistence.PreRemove");
    stringBuffer.append(TEXT_87);
    for (Iterator i=ClassHelper.getAllManyToManyProperties(uml2Class); i.hasNext();) { Property property = (Property)i.next();
    if (ClassHelper.isSource(property)) {
    stringBuffer.append(TEXT_88);
    stringBuffer.append(NameHelper.getCapName(property));
    stringBuffer.append(TEXT_89);
    }}
    for (Iterator i=ClassHelper.getAllOneToManyProperties(uml2Class); i.hasNext();) { Property property = (Property)i.next();
    if (ClassHelper.isShared(property)) {
    stringBuffer.append(TEXT_90);
    stringBuffer.append(NameHelper.getCapName(property));
    stringBuffer.append(TEXT_91);
    }}
    stringBuffer.append(TEXT_92);
    }
    stringBuffer.append(TEXT_93);
    if (StereotypeHelper.isStereotypeApplied(uml2Class, StereotypeHelper.ENTITY)) {
    stringBuffer.append(TEXT_94);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_95);
    if (ClassHelper.hasSuperClass(uml2Class)) {
    stringBuffer.append(TEXT_96);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_97);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_98);
    } else {
    stringBuffer.append(TEXT_99);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_100);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_101);
    }
    for (Iterator i=ClassHelper.getOwnedOneToManyProperties(uml2Class); i.hasNext();) { Property property = (Property)i.next();
    stringBuffer.append(TEXT_102);
    stringBuffer.append(NameHelper.getCapName(property));
    stringBuffer.append(TEXT_103);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_104);
    stringBuffer.append(NameHelper.getCapName(property));
    stringBuffer.append(TEXT_105);
    stringBuffer.append(ClassHelper.getAccessorNameNonPlural(property));
    stringBuffer.append(TEXT_106);
    }
    for (Iterator i=ClassHelper.getOwnedOneToOneProperties(uml2Class); i.hasNext();) { Property property = (Property)i.next();
    stringBuffer.append(TEXT_107);
    stringBuffer.append(NameHelper.getCapName(property));
    stringBuffer.append(TEXT_108);
    stringBuffer.append(NameHelper.getCapName(property));
    stringBuffer.append(TEXT_109);
    }
    for (Iterator i=ClassHelper.getOwnedManyToManyProperties(uml2Class); i.hasNext();) { Property property = (Property)i.next();
    stringBuffer.append(TEXT_110);
    stringBuffer.append(NameHelper.getCapName(property));
    stringBuffer.append(TEXT_111);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_112);
    stringBuffer.append(NameHelper.getCapName(property));
    stringBuffer.append(TEXT_113);
    stringBuffer.append(ClassHelper.getAccessorNameNonPlural(property));
    stringBuffer.append(TEXT_114);
    }
    stringBuffer.append(TEXT_115);
    }
    if (StereotypeHelper.isStereotypeApplied(uml2Class, StereotypeHelper.ENTITY) && !ClassHelper.hasSuperClass(uml2Class)) {
    stringBuffer.append(TEXT_116);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_117);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_118);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_119);
    }
    stringBuffer.append(TEXT_120);
    importStringBuffer.insert(importInsertionPoint, importManager.computeSortedImports());
    stringBuffer.append(TEXT_121);
    return stringBuffer.toString();
  }
}
